home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI SNMP Access to HP-UX MIB 1.1.2
/
SGI SNMP Access to HP-UX MIB 1.1.2.iso
/
dist
/
pcp_eoe.idb
/
etc
/
init.d
/
pcp.z
/
pcp
Wrap
Text File
|
1998-04-24
|
12KB
|
486 lines
#!/sbin/sh
#
# Start or Stop the Performance Co-Pilot Daemon(s)
#
# $Id: etc_init.d_pcp,v 2.65 1998/03/03 01:02:40 kenmcd Exp $
#
# Some degree of paranoia here ...
PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/pcp/bin
export PATH
IS_ON=/sbin/chkconfig
PMCD=/usr/etc/pmcd
OLDPMCD=/var/pcp/lib/pmcd
PMCDOPTS=/etc/config/pmcd.options
RUNDIR=${PCP_LOGDIR-/var/adm/pcplog}
DKPROBE=/usr/pcp/bin/dkprobe
PMLOGGER=/usr/pcp/bin/pmlogger
PMCHECK=/usr/pcp/bin/cron.pmcheck
prog=/etc/init.d/`basename $0`
PCPLOCAL=/var/pcp/etc/local
tmp=/var/tmp/$$
status=1
trap "rm -f $tmp.* ; exit \$status" 0 1 2 3 15
# determine real name for localhost
#
LOCALHOSTNAME="localhost"
[ -x /usr/bsd/hostname ] && LOCALHOSTNAME=`/usr/bsd/hostname`
LOGDIR=${PCP_LOGDIR-/var/adm/pcplog}/$LOCALHOSTNAME
if $IS_ON verbose
then # For a verbose startup and shutdown
ECHO=echo
REBUILDOPT=''
else # For a quiet startup and shutdown
ECHO=:
REBUILDOPT=-s
fi
id=`id | sed -e "s/(.*//" -e "s/.*=//"`
if [ "$id" != 0 ]
then
echo "$prog:"'
Error: You must be root (uid 0) to start or stop the Performance Co-Pilot PMCD.'
exit
fi
_pmcd_logfile()
{
default=$RUNDIR/pmcd.log
nawk <$PMCDOPTS '
BEGIN { logf = "'$default'" }
$1 == "-l" { if (NF > 1) logf = $2 }
END { print logf }'
}
_no_libirixpmda()
{
logger -p user.alert -t PCP "pmcd: $1 missing"
echo \
'Error: Cannot find '"$1"'
PMCD will start but will not export any IRIX metrics.'
}
_no_lib64_pcp()
{
logger -p user.alert -t PCP "pmcd: /usr/lib64/libpcp.so.2 missing"
echo \
'Error: Cannot find /usr/lib64/libpcp.so.2 , cannot start PMCD.
You should use inst(1)/swmgr(1) to ensure that the pcp_eoe.sw64.lib
subsystem is installed.'
exit
}
_reboot_setup()
{
# Set up libirixpmda link so that pmcd will find it
# Only needed for 5.3, but removed for all OSs first as previous
# releases created it
#
rm -f /var/pcp/lib/libirixpmda.so /var/pcp/lib/mips_*.libirixpmda.so
irix_version=`/sbin/uname -r`
irix_obj=`/usr/pcp/bin/pmobjstyle`
if [ "$irix_obj" = mips_64 -a ! -f /usr/lib64/libpcp.so.2 ]
then
_no_lib64_pcp
fi
case $irix_version
in
5.3) if [ ! -f /usr/lib/pcp/libirixpmda.so ]
then
_no_libirixpmda /usr/lib/pcp/libirixpmda.so
echo \
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
to ensure that IRIX patch 2825 (or a successor) is installed.
'
else
ln -s /usr/lib/pcp/libirixpmda.so /var/pcp/lib/mips_o32.libirixpmda.so
fi
;;
6.2)
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
then
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
echo \
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
to ensure that IRIX patch 2826 (or a successor) is installed.
'
fi
;;
6.3)
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
then
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
echo \
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
to ensure that IRIX patch 2827 (or a successor) is installed.
'
fi
;;
6.4)
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
then
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
echo \
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
to ensure that IRIX patch 2828 (or a successor) is installed.
'
fi
;;
6.5)
if [ ! -f /usr/pcp/lib/$irix_obj.libirixpmda.so ]
then
_no_libirixpmda /usr/pcp/lib/$irix_obj.libirixpmda.so
echo \
' To obtain an appropriate libirixpmda you should use inst(1)/swmgr(1)
to ensure that the pcp_eoe.sw.eoe subsystem from the IRIX 6.5 CD set
is installed.
'
fi
;;
esac
# base directories and house-keeping for pmlogger instances
#
if [ ! -d /var/tmp/pmlogger ]
then
mkdir /var/tmp/pmlogger
else
rm -rf $tmp.ent $tmp.pid
here=`pwd`
cd /var/tmp/pmlogger
rm -f primary vcr
ps -ef | grep pmlogger | grep -v grep | nawk '{ print $2 }' \
| sed -e 's/[ ]*//g' | sort >$tmp.pid
ls [0-9]* 2>&1 | sed -e '/\[0-9]\*/d' \
| sed -e 's/[ ][ ]*//g' | sort >$tmp.ent
# remove entries without a pmlogger process
rm -f `comm -23 $tmp.ent $tmp.pid`
rm -f $tmp.ent $tmp.pid
cd $here
fi
chmod 1777 /var/tmp/pmlogger
[ ! -d $LOGDIR ] && mkdir -p $LOGDIR
# Rebuild PMNS?
#
PMNSDIR=/var/pcp/pmns
if [ -d $PMNSDIR -a -f $PMNSDIR/.NeedRebuild ]
then
if [ -x $PMNSDIR/Rebuild ]
then
$ECHO "Performance Co-Pilot rebuilding PMNS ..."
here=`pwd`
cd $PMNSDIR
./Rebuild -du $REBUILDOPT
[ $? -eq 0 ] && rm -f .NeedRebuild
cd $here
fi
fi
# Update /etc/magic?
#
MAGICDIR=/var/pcp/config/magic
if [ -d $MAGICDIR -a -f $MAGICDIR/.NeedUpdate ]
then
if [ -x $MAGICDIR/update-magic ]
then
$ECHO "Performance Co-Pilot updating /etc/magic entries ..."
here=`pwd`
cd $MAGICDIR
./update-magic
[ $? -eq 0 ] && rm -f .NeedUpdate
cd $here
fi
fi
}
_start_pmlogger()
{
[ ! -d /var/tmp/pmlogger ] && mkdir /var/tmp/pmlogger
chmod 1777 /var/tmp/pmlogger
# wait for PMCD to make with the metrics, daddyo
# ... 30 seconds should suffice
#
notfound=true
for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do
if pminfo -f pmcd.numagents 2>&1 | egrep 'value [0-9]*' >/dev/null 2>&1
then
notfound=false
break
fi
sleep 2
done
if $notfound
then
echo "$prog:"'
Warning: Unable to contact PMCD, suggesting that PMCD may not have started.
Check the file "'"`_pmcd_logfile`"'" for possible
errors and/or warnings.
No attempt will be made to start the Performance Co-Pilot archive
logger(s).'
return
fi
if [ -x $PMCHECK ]
then
if fgrep -s 'getopts l: c' $PMCHECK
then
# this is the PCP 1.3 version that is not reliable ...
# better to warn and not start the primary logger than
# die mysteriously trying
echo "$prog:"'
Warning: Performance Co-Pilot installation is incomplete (the script
"'$PMCHECK'" appears to be from an earlier PCP
distribution) and the PCP archive logger(s) cannot be started.
You should install the pcp.sw.base from the PCP 2.0 distribution,
else
# /sbin/chkconfig pmlogger off'
return
fi
# $PMCHECK uses /var/pcp/config/pmlogger/control
# and so can start everything that is needed
$ECHO "Performance Co-Pilot starting archive loggers ..."
if [ ! -f /var/pcp/config/pmlogger/control ]
then
echo "$prog:"'
Error: PCP archive logger control file /var/pcp/config/pmlogger/control
is missing! Cannot start any Performance Co-Pilot archive logger(s).'
return
fi
if grep '^LOCALHOSTNAME[ ]*y[ ]' /var/pcp/config/pmlogger/control >/dev/null
then
:
elif grep "^$LOCALHOSTNAME[ ]*y[ ]" /var/pcp/config/pmlogger/control >/dev/null
then
:
else
echo "$prog"'
Info: Initializing default PCP archive logger control for the primary
logger in the file /var/pcp/config/pmlogger/control - see
cron.pmcheck(1) for details.
This is a once only initialization after a PCP upgrade.'
if [ -f /etc/config/pmlogger.options ]
then
options=`sed </etc/config/pmlogger.options \
-e '/^#/d' \
-e 's/^/ /' \
-e 's/$/ /' \
-e 's/ -P / /g' \
-e 's/^ //' \
-e 's/ $//'`
else
options=''
fi
[ -z "$options" ] && options="-c config.default"
ex - /var/pcp/config/pmlogger/control <<End-of-File
g/^#LOCALHOSTNAME[ ]*y[ ]/d
g/^# local primary logger/d
\$a
# local primary logger
# /etc/init.d/pcp added this default configuration
# on `date`
LOCALHOSTNAME y n /var/adm/pcplog/LOCALHOSTNAME $options
.
w!
q
End-of-File
fi
$PMCHECK
return
else
echo "$prog:"'
Warning: Performance Co-Pilot installation is incomplete (at least the
script "'$PMCHECK'" is missing) and the PCP archive
logger(s) cannot be started.
You should install the pcp.sw.base from the PCP 2.0 distribution
and consult cron.pmcheck(1), else
# /sbin/chkconfig pmlogger off'
fi
}
# Use /etc/pmcd.conf to find and kill pipe/socket PMDAs created by PMCD.
# (First join up continued lines in config file)
#
_killpmdas()
{
if [ ! -f /etc/pmcd.conf ]
then
echo "$prog:"'
Warning: PMCD control file "/etc/pmcd.conf" is missing, cannot identify PMDAs
to be terminated.'
return
fi
for pmda in `nawk </etc/pmcd.conf '
/\\\\$/ { printf "%s ", substr($0, 0, length($0) - 1); next }
{ print }' \
| nawk '
$1 ~ /^#/ { next }
tolower($3) == "pipe" && NF > 4 { print $5; next }
tolower($3) == "socket" && NF > 5 { print $6; next }' \
| sort -u`
do
# Give each PMDA 2 seconds after a SIGTERM to die, then SIGKILL
killall -k 2 -TERM `basename $pmda` &
done
wait
}
_shutdown()
{
# Send pmcd a SIGTERM, which is noted as a pending shutdown.
# When finished the currently active request, pmcd will close any
# connections and then exit.
# Wait for pmcd to terminate, make sure any agents pmcd has
# created are dead.
#
killall -TERM pmcd
$ECHO "Waiting for PMCD to terminate ...\c"
gone=0
for i in 1 2 3 4 5 6
do
sleep 3
ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
if [ ! -s $tmp.tmp ]
then
gone=1
break
fi
# If they don't go in 15 seconds, SIGKILL and sleep 1 more time
# to allow any clients reading from PMCD sockets to fail so that
# socket doesn't end up in TIME_WAIT or somesuch.
#
if [ $i = 5 ]
then
$ECHO
echo "Process ..."
cat $tmp.tmp
echo "$prog: Warning: Forcing PMCD to terminate!"
killall -KILL pmcd
else
$ECHO ".\c"
fi
done
$ECHO
_killpmdas
if [ $gone != 1 ] # It just WON'T DIE, give up.
then
echo "Process ..."
cat $tmp.tmp
echo "$prog: Warning: PMCD won't die!"
exit
fi
pmpost "stop pmcd from /etc/init.d/pcp"
}
case "$1" in
'start')
ps -ef | egrep "($PMCD)|($OLDPMCD)" | grep -v grep >$tmp.tmp 2>&1
[ -s $tmp.tmp ] && _shutdown
# PMCD and PMDA messages should go to stderr, not the GUI notifiers
#
unset PCP_STDERR
_reboot_setup
if [ -d /hw/rdisk ]
then
# assume this is a system with the hardware graph support,
# so dkprobe is not required
:
else
# touch all the disks so that libirixpmda sees them
[ -x $DKPROBE ] && $DKPROBE
fi
if [ -x $PMCD ]
then
if $IS_ON pmcd
then
if [ ! -f /etc/pmcd.conf ]
then
echo "$prog:"'
Error: PMCD control file "/etc/pmcd.conf" is missing, cannot start PMCD.'
exit
fi
cd $RUNDIR
# salvage the previous versions of any PMCD and PMDA logfiles
#
for log in pmcd `sed -e '/^#/d' -e '/\[access\]/q' -e 's/[ ].*//' </etc/pmcd.conf`
do
if [ -f $log.log ]
then
rm -f $log.log.prev
mv $log.log $log.log.prev
fi
done
$ECHO "Performance Co-Pilot starting PMCD (logfile is `_pmcd_logfile`) ..."
OPTS=`sed -e '/^#/d' -e 's/-f//' $PMCDOPTS 2> /dev/null`
if [ `uname -r | tr -c '.\012[0-9]' ' ' | sed -e 's/ .*//' | nawk -F. '{ print $1*100+$2 }'` -ge 605 ]
then
# IRIX6.5 or later
/sbin/suattr -C CAP_SETGID+ip -c "$PMCD `echo $OPTS`"
else
$PMCD `echo $OPTS`
fi
pmpost "start pmcd from /etc/init.d/pcp"
if [ -x $PMLOGGER ]
then
if $IS_ON pmlogger
then
_start_pmlogger
else
# forced removal of primary symlink
rm -f /var/tmp/pmlogger/primary
fi
fi
# site-local customisations after PCP startup
#
[ -x $PCPLOCAL ] && $PCPLOCAL start
else
if [ "$0" = "/etc/init.d/pcp" ]
then
echo "$prog:"'
Warning: Performance Co-Pilot collector (PMCD) is disabled. To enable:
# /sbin/chkconfig pmcd on'
fi
fi
fi
status=0
;;
'stop')
# site-local customisations before PCP shutdown
#
[ -x $PCPLOCAL ] && $PCPLOCAL stop
_shutdown
status=0
;;
*)
echo "Usage: /etc/init.d/pcp {start|stop}"
;;
esac